/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#include <gtest/gtest.h>
#include <mc/common.h>
#include <mc/memory.h>

#include "../../../../../drivers/pcie_nic_card/wx/interface/pcie_card.h"

namespace {

// Test fixture
class pcie_card_test : public ::testing::Test {
protected:
    void SetUp() override {
        m_pcie_card = mc::make_shared<dev::PCIeCard>();
    }

    void TearDown() override {
        m_pcie_card.reset();
    }

    mc::shared_ptr<dev::PCIeCard> m_pcie_card;
};

// ========== PCIeCard 基本功能测试 ==========

TEST_F(pcie_card_test, Constructor) {
    // 目标：验证 PCIeCard 接口可以正常构造
    dev::PCIeCard card;
    EXPECT_TRUE(true);
}

TEST_F(pcie_card_test, Destructor) {
    // 目标：验证 PCIeCard 接口可以正常析构
    {
        dev::PCIeCard card;
    }
    EXPECT_TRUE(true);
}

TEST_F(pcie_card_test, SystemId_Property) {
    // 目标：验证 PCIeCard 接口的 SystemId 属性可以正常访问和设置
    m_pcie_card->SystemId = 1;
    EXPECT_EQ(m_pcie_card->SystemId, 1);
    
    m_pcie_card->SystemId = 2;
    EXPECT_EQ(m_pcie_card->SystemId, 2);
}

TEST_F(pcie_card_test, SystemId_BoundaryValues) {
    // 目标：验证 PCIeCard 接口的 SystemId 属性可以处理边界值
    m_pcie_card->SystemId = 0;
    EXPECT_EQ(m_pcie_card->SystemId, 0);
    
    m_pcie_card->SystemId = 255;  // uint8_t 最大值
    EXPECT_EQ(m_pcie_card->SystemId, 255);
}

TEST_F(pcie_card_test, MultipleInstances) {
    // 目标：验证可以创建多个 PCIeCard 实例
    std::vector<mc::shared_ptr<dev::PCIeCard>> cards;
    
    for (int i = 0; i < 3; ++i) {
        auto card = mc::make_shared<dev::PCIeCard>();
        card->SystemId = static_cast<uint8_t>(i);
        cards.push_back(card);
    }
    
    EXPECT_EQ(cards.size(), 3);
    EXPECT_EQ(cards[0]->SystemId, 0);
    EXPECT_EQ(cards[1]->SystemId, 1);
    EXPECT_EQ(cards[2]->SystemId, 2);
}

} // namespace

